package dfsketches.gr3d;

import java.util.Arrays;
import java.util.Vector;

public class BoneConstructor {

	Vector<Vertex> vertices;
	Vector<Bone> subBones;
	
	public BoneConstructor() {
		vertices = new Vector<Vertex>();
		subBones = new Vector<Bone>();
	}
	
	public void addVertex(Vertex v) {
		vertices.add(v);
	}
	
	public Vertex addCopyOfVertex(Vertex v) {
		Vertex copy = new Vertex(v);
		vertices.add(copy);
		return copy;
	}
	
	public void addSubBone(Bone b) {
		subBones.add(b);
	}
	
	public Vertex[] addRectangle(Vertex base, Vector3D dim1, Vector3D dim2) {
		Vertex[] rect = new Vertex[4];
		rect[0] = base;
		rect[1] = Vertex.getSum(base, dim1);
		rect[2] = Vertex.getSum(base, dim2);
		rect[3] = Vertex.getSum(base, dim1); rect[3].add(dim2);
		vertices.addAll(Arrays.asList(rect));
		return rect;
	}
	
	public Vertex[] addBox(Vertex base, Vector3D dim1, Vector3D dim2, Vector3D dim3) {
		Vertex[] rect = new Vertex[8];
		rect[0] = base;
		rect[1] = Vertex.getSum(base, dim1);
		rect[2] = Vertex.getSum(base, dim2);
		rect[3] = Vertex.getSum(rect[1], dim2);
		rect[4] = Vertex.getSum(rect[0], dim3);
		rect[5] = Vertex.getSum(rect[1], dim3);
		rect[6] = Vertex.getSum(rect[2], dim3);
		rect[7] = Vertex.getSum(rect[3], dim3);
		vertices.addAll(Arrays.asList(rect));
		return rect;
	}
	
	public Bone construct() {
		Bone bone = new Bone(vertices, subBones);
		return bone;
	}
	
}
